package com.Mybatis3源码深度解析.c2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Properties;

import org.apache.ibatis.io.Resources;
import org.junit.Test;

/**
 * 通过ParameterMetaData获取参数信息
 */
public class PreparedStatementDemo {

    @Test
    public void testJdbc() {
        try {
        	// 初始化数据
            Class.forName("com.mysql.jdbc.Driver");
            Properties prop = Resources.getResourceAsProperties("hikariPool.properties");
            // 获取Connection对象
            Connection connection = DriverManager.getConnection(prop.getProperty("jdbcUrl"), prop.getProperty("dataSource.user"), prop.getProperty("dataSource.password"));
            PreparedStatement stmt = connection.prepareStatement("insert into  " +
                    "test(id, title) " +
                    "values(?,?);");
            stmt.setInt(1, 2);
            stmt.setString(2, "Mybatis3源码深度解析");
            stmt.execute();
            stmt.setInt(1, 3);
            stmt.setString(2, "Mybatis3源码深度解析");
            stmt.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
